<div class="content">
	<div id="left-column">
		<?php echo $this->element('left_column')?>		
	</div>
		
	<div class="right-store-column">	
	<div class="storeOrders view">
	<h2><?php  __d('store','Order');?></h2>
		<table>
			<tr>
				<th valign="top" align="right"><?php __d('store','Id:'); ?></th>
				<td><?php echo $storeOrder['StoreOrder']['id']; ?>&nbsp;</td>
			</tr>
			<tr>
				<th valign="top" align="right"><?php __d('store','Billing Address:'); ?></th>
				<td>
					<?php echo $this->Html->link($storeOrder['User']['email'], array('controller' => 'users', 'action' => 'view', $storeOrder['User']['id'])); ?><br/>
					<?php 
						if(isset($storeOrder['User']['Customer'][0]['user_id']) && $storeOrder['User']['Customer'][0]['user_id'] == $storeOrder['User']['id']){
							$model = 'Customer';
						}else{
							$model = 'Employee';
						}
						echo $storeOrder['User'][$model][0]['name'] . ' ' . $storeOrder['User'][$model][0]['surname'].'<br/>';
						echo $storeOrder['User'][$model][0]['address1'] . ' ' . $storeOrder['User'][$model][0]['address2'].'<br/>';
						echo $storeOrder['User'][$model][0]['address3'] . ' ' . $storeOrder['User'][$model][0]['address4'].'<br/>';
						echo $storeOrder['User'][$model][0]['address5'] . ' ' . $storeOrder['User'][$model][0]['phone1'].'<br/>';
					?>
					&nbsp;
				</td>
			</tr>
			<?php if(!$storeOrder['StoreOrder']['delivery_as_billing']){?>
			<tr>
				<th valign="top" align="right"><?php __d('store','Delivery Address:'); ?></th>
				<td>
					<?php 
						echo $storeOrder['StoreOrder']['delivery_name'] . ' ' . $storeOrder['StoreOrder']['delivery_surname'].'<br/>';
						echo $storeOrder['StoreOrder']['delivery_address1'] . ' ' . $storeOrder['StoreOrder']['delivery_address2'].'<br/>';
						echo $storeOrder['StoreOrder']['delivery_address3'] . ' ' . $storeOrder['StoreOrder']['delivery_address4'].'<br/>';
						echo $storeOrder['StoreOrder']['delivery_address5'];
					?>
					&nbsp;
				</td>
			</tr>
			<?php }?>
			<tr>
				<th valign="top" align="right"><?php __d('store','Added:'); ?></th>
				<td><?php echo $storeOrder['StoreOrder']['added']; ?>&nbsp;</td>
			</tr>
			<tr>
				<th valign="top" align="right"><?php __d('store','Status:'); ?></th>
				<td><?php echo $storeOrder['StoreOrder']['status']; ?>&nbsp;<?php echo $storeOrder['StoreOrder']['status_detail']; ?></td>
			</tr>
			<tr>
				<th valign="top" align="right"><?php __d('store','Nout:'); ?></th>
				<td><?php echo $storeOrder['StoreOrder']['order_nout']; ?>&nbsp;</td>
			</tr>
		</table>
	</div>
	
	<div class="related">
		<h3><?php __('Order Details');?></h3>
		<?php if (!empty($storeOrder['StoreProduct'])):?>
		<table class="index" cellpadding = "0" cellspacing = "0" width="100%">
		<tr>
			<th><?php __('Id'); ?></th>
			<th><?php __('Name'); ?></th>
			<th><?php __('Type'); ?></th>
			<th><?php __('Amount'); ?></th>
			<th><?php __('Price'); ?></th>
			<th class="actions"><?php __('Actions');?></th>
		</tr>
		<?php
			$i = 0;
			foreach ($storeOrder['StoreProduct'] as $product):
				$class = null;
				if ($i++ % 2 == 0) {
					$class = ' class="altrow"';
				}
			?>
			<tr<?php echo $class;?>>
				<td><?php echo $product['id'];?></td>
				<td><?php echo $html->link($product['name'],array('controller'=>'products','action'=>'edit',$product['id']));?></td>
				<td>
					<?php 
					foreach ($storeOrder['StoreType'] as $key => $typ) {
						if($typ['id'] == $product['StoreOrderDetail']['type_id'] ){
							echo $typ['name'];
							
							break;
						}
					}
					?>
				</td>
				<td align="right"><?php echo $product['StoreOrderDetail']['ilosc'];?></td>
				<td align="right">
					<?php if($product['price_przecena'] > 0 && $product['price_promocja'] == 0){?>						
							<span class="product-view-price"><?php echo $this->Store->price($product['price_przecena'],2,null,null,$product['currency_id'],$product['StoreOrderDetail']['exchange'],null,null,'.')?></span>
					<?php }else if( $product['price_promocja'] > 0){?>						 
							<span class="product-view-price"><?php echo $this->Store->price($product['price_promocja'],2,null,null,$product['currency_id'],$product['StoreOrderDetail']['exchange'],null,null,'.')?></span>
					<?php }else{?>
							<span class="product-view-price"><?php echo $this->Store->price($product['price_detaliczna'],2,null,null,$product['currency_id'],$product['StoreOrderDetail']['exchange'],null,null,'.')?></span>
					<?php }?>
				</td>
				<td class="actions" align="right">
					<?php //echo $this->Html->link(__('Edit', true), array('controller' => 'groups', 'action' => 'edit', $product['id'])); ?>
					<?php //echo $this->Html->link(__('Delete', true), array('controller' => 'groups', 'action' => 'delete', $product['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $product['id'])); ?>
				</td>
			</tr>
		<?php endforeach; ?>
		</table>
	<?php endif; ?>
	
	</div>
</div>	
	<?php if($session->check('Auth.User.id')){?>
	<?php echo $this->element('toolbar_actions_main',array('plugin'=>'store','toolbar'=>'orders'))?>
	<?php }?>